/**
 * Constants and Utility functions.
 */
var operatorForDataType = {
	'string':[
	          ['equals','='], ['not equals', '!='], ['starts with','st'], ['ends with','ew'], ['contains','con']
	         ],
	'integer' : [
	             ['equals','='], ['not equals', '!='], ['less than','<'], ['less than or equal','<='], 
	             ['greater than','>'], ['greater than or equal','>=']
	            ],
	'decimal': [
	             ['equals','='], ['not equals', '!='], ['less than','<'], ['less than or equal','<='], 
	             ['greater than','>'], ['greater than or equal','>=']
	           ],
	'list':	[
	       	 ['equals','='], ['not equals', '!='], ['starts with','st'], ['ends with','ew'], ['contains','con']
	       	],
	'date':	[ 
	       	  ['equals','='], ['not equals', '!='], ['less than','<'], ['less than or equal','<='], 
	             ['greater than','>'], ['greater than or equal','>=']
             ],
	'timestamp': [ 
	               ['equals','='], ['not equals', '!='], ['less than','<'], ['less than or equal','<='], 
		             ['greater than','>'], ['greater than or equal','>=']
	             ]
};

var propertyLocation = [];

function loadOperators(datatype, loadfield){
	operators = operatorForDataType[datatype];
	options = "";
	for(var ops in operators){
		options = options + '<option value="'+operators[ops][1]+'">'+operators[ops][0]+'</option>';
	}
	$('#'+loadfield).html(options);
}

function loadEditor(datatype, field){
	switch(datatype){
	case 'string':
		$("#"+field).val("");
				$("#"+field).replaceWith('<input type="text" id="Criteria_prop_val" name="Criteria[prop_val]" maxlength="100" size="60">');
			break;
	case 'integer':
			$("#"+field).val("");
			$("#"+field).replaceWith('<input type="text" id="Criteria_prop_val" name="Criteria[prop_val]" maxlength="100" size="60">');
			break;
	case 'decimal':
			$("#"+field).val("");
			$("#"+field).replaceWith('<input type="text" id="Criteria_prop_val" name="Criteria[prop_val]" maxlength="100" size="60">');
			break;
	case 'list':
			$("#"+field).val("");
			$("#"+field).replaceWith('<input type="text" id="Criteria_prop_val" name="Criteria[prop_val]" maxlength="100" size="60">');
			break;
	case 'date':
			$("#"+field).val("");
			//$("#"+field).replaceWith('<input type="text" id="Criteria_prop_val" name="Criteria[prop_val]" maxlength="100" size="60">');
			$("#"+field).datetimepicker({
				lang:'en',
				timepicker:false,
				format:'m/d/Y',
				onSelectDate:function(c,inp){
					//console.log("c:"+c+"\ninp:"+inp);
					//$("#"+field).val(c.format0());
				}
			});
			break;
	case 'timestamp':
			$("#"+field).val("");
			//$("#"+field).replaceWith('<input type="text" id="Criteria_prop_val" name="Criteria[prop_val]" maxlength="100" size="60">');
			$("#"+field).datetimepicker({
				dayOfWeekStart : 0,
				lang:'en',
				//disabledDates:['1986/01/08','1986/01/09','1986/01/10'],
				//startDate:	'1990/01/01'
			});
			break;
	default:
			console.log("Invalid Operator...");
	}
}